//
//  CZMainViewController.swift
//  CZXSWWeibo007
//
//  Created by xushengwei on 15/12/16.
//  Copyright © 2015年 xushengwei. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar = CZMainTabBar()
        setValue(mainTabbar, forKey: "tabBar")
        

        let homeVC = CZHomeViewController()
        self.addChildVC(homeVC, title: "首页", imageName: "tabbar_home")
        
        let messageVC = CZMessageViewController()
        self.addChildVC(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        let discoveryVC = CZDiscoveryViewController()
        self.addChildVC(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC = CZProfileViewController()
        self.addChildVC(profileVC, title: "我", imageName: "tabbar_profile")
        
    }
    
    private func addChildVC(controller: UIViewController, title: String, imageName: String){
        //包装导航控制器
        self.addChildViewController(UINavigationController(rootViewController: controller))
        
        //设置title
        controller.title = title
        
        //设置背景图片
        controller.tabBarItem.image = UIImage(named: imageName)
        
        //设置高亮状态的背景图片
        let highLightedName = imageName + "_highlighted"
        controller.tabBarItem.selectedImage = UIImage(named: highLightedName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置文件颜色
        // NSForegroundColorAttributeName: 设置文字的前景颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
    }


}
